home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Scripting_Resources / Samples / Automation_Scripts / Complex Animation.js < prev    next >
Encoding:
Text File  |  2002-05-13  |  3.9 KB  |  108 lines

  1. //////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED 
  4. // Copyright 2002 Adobe Systems Incorporated 
  5. // All Rights Reserved 
  6. //
  7. // NOTICE:  Adobe permits you to use, modify, and 
  8. // distribute this file in accordance with the terms
  9. // of the Adobe license agreement accompanying it.  
  10. // If you have received this file from a source 
  11. // other than Adobe, then your use, modification,
  12. // or distribution of it requires the prior 
  13. // written permission of Adobe. 
  14. //
  15. //////////////////////////////////////////////////
  16.  
  17. //////////////////////////////////////////////////
  18. // 
  19. // Complex Animation.js
  20. //
  21. // DESCRIPTION
  22. //
  23. // This script uses a mathematical formula to apply
  24. // motion to an object and creates more key frames. 
  25. // It also shows how to apply similar principals to 
  26. // other stopwatches.
  27. //
  28. // HOW TO USE
  29. //
  30. // Create any object and select it in the Composition.
  31. // Select Automation > Run Automation Script > Complex Animation.js
  32. // Click on Preview Mode to view the object animation.
  33. //
  34. //////////////////////////////////////////////////
  35.  
  36. // Main Code [Execution of script begins here]
  37.  
  38. // Check if any composition is open
  39. if(application.compositions.length > 0){
  40.     comp = application.currentComposition;
  41.     if(comp.selection.length >= 1){ // Checks if at least one object is selected
  42.         var objs = comp.selection; // Store all selected objects in the array objs
  43.         for(var i=0 ; i < objs.length ; i++){
  44.             // Assign the objects in objs, one by one to target and apply complex animation to them
  45.             target = objs[i]; 
  46.             application.currentComposition.saveSelection(); // saves the current selection
  47.             complexAnimation(target, 50, 50, 36); // Function complexAnimation called
  48.             application.currentComposition.restoreSelection(); // restores the saved selection
  49.         }
  50.     }
  51.     else{ // If no objects are selected brings the Console window up 
  52.         Console.show();
  53.         // Writes to the Console
  54.         Console.write("Please select the objects to apply the Animation and run the script again.\n");
  55.     }
  56. }
  57. else{// if no composition open
  58.     // opens a new composition
  59.     comp = application.newComposition();
  60.     Console.show();
  61.     Console.write("New Composition opened\nPlease create and select the objects to apply the Animation and run the script again.\n");
  62. }
  63.  
  64.  
  65. // Add your own functions here
  66.  
  67. //////////////////////////////////////////////////
  68. //
  69. // complexAnimation:
  70. //
  71. // Animates the currently selected object using a 
  72. // mathematical formula
  73. //
  74. // target: The object to animate.
  75. // x: The change in x position.
  76. // y: The change in y position.
  77. // frames: Total number of frames throughout which the animation will last.
  78. //
  79. //////////////////////////////////////////////////
  80.  
  81. function complexAnimation(target, x, y, frames)
  82. {
  83.     var x_original; // variable for the original x position
  84.     var y_original; // variable for the original y position    
  85.     var frame0; // the initial / current frame to start the animation from 
  86.     var keyFrameRate = 3; // this script will create a key frame every 3 frames
  87.     
  88.     frame0 = target.startFrame; // take the current frame value and store it
  89.     x_original = target.position.x; // store initial x position
  90.     y_original = target.position.y; // store initial y position
  91.  
  92.     target.stopwatch.position = true; // turn on the stopwatch for position
  93.     target.stopwatch.rotation = true; // turn on the stopwatch for rotation    
  94.     
  95.     // Note: The initial positions are not stored by turning on the stopwatch. 
  96.     // The stopwatch only records changes AFTER it's been turned on.
  97.     
  98.     // loop to animate the object across the frames
  99.     for (var i=0 ; i < frames ; i += keyFrameRate) {
  100.         target.currentFrame = frame0 + i; // First frame
  101.         target.position.x = x_original + x * Math.sin((i/frames) * (2 * Math.PI));
  102.         target.position.y = y_original + y * Math.cos((i/frames) * (2 * Math.PI));
  103.         target.rotation = (i / frames) * 720;
  104.     }
  105.     return;
  106. }
  107.  
  108.